package com.quanyan.stadium.service.gameLevelScore.impl;

import com.quanyan.stadium.constants.GameConstants;
import com.quanyan.stadium.service.gameLevelScore.LScore;
import com.quanyan.stadium.service.gameLevelScore.utils.GameLScoreUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by xiaoxiao on 16/12/22.
 *
 * 非标准等级分计算
 */
@Service
public class FLScore extends LScore{

    /**
     * 计算非标准等级分变化量
     *
     * */
    @Override
    public double calculateLScoreInc(Map<String, Object> LScoreParams) {
        Byte categoryId = (Byte) LScoreParams.get("categoryId");
        double res = 0.00;
        if (categoryId == GameConstants.CATEGORY_ID_TENNIS) {
            res = calculateTenLScoreInc(LScoreParams);
        }else if (categoryId == GameConstants.CATEGORY_ID_BADMINTON) {
            res = calculateBadLScoreInc(LScoreParams);
        }else if (categoryId == GameConstants.CATEGORY_ID_BASKETBALL) {
            res = calculateBasLScoreInc(LScoreParams);
        }else if (categoryId == GameConstants.CATEGORY_ID_FOOTBALL) {
            res = calculateFooLScoreInc(LScoreParams);
        }
        return res;

    }

    private double calculateTenLScoreInc (Map<String, Object> LScoreParams){
        Double ownLScore = (Double) LScoreParams.get("ownLScore");
        Double oppLScore = (Double) LScoreParams.get("oppLScore");
        Integer p = (Integer) LScoreParams.get("p");
        Byte categoryId = (Byte) LScoreParams.get("categoryId");

        double a = GameLScoreUtils.getK()*GameLScoreUtils.getG(categoryId, p)*(6000-ownLScore)/2500*(GameLScoreUtils.getW(p)-GameLScoreUtils.getWe(ownLScore, oppLScore));
        double b = (ownLScore - oppLScore > 0)?(int)((ownLScore-oppLScore)/1000)*100*(1-GameLScoreUtils.getW(p)):0.00;
        return GameLScoreUtils.getLScoreIncrement(a, b);
    }

    private double calculateBadLScoreInc (Map<String, Object> LScoreParams){
        Double ownLScore = (Double) LScoreParams.get("ownLScore");
        Double oppLScore = (Double) LScoreParams.get("oppLScore");
        Integer p = (Integer) LScoreParams.get("p");
        Byte categoryId = (Byte) LScoreParams.get("categoryId");

        double a = GameLScoreUtils.getK()*GameLScoreUtils.getG(categoryId, p)*(11000-ownLScore)/5000*(GameLScoreUtils.getW(p)-GameLScoreUtils.getWe(ownLScore, oppLScore));
        double b = (ownLScore - oppLScore > 0)?(int)((ownLScore-oppLScore)/2000)*100*(1-GameLScoreUtils.getW(p)):0.00;
        return GameLScoreUtils.getLScoreIncrement(a, b);
    }

    private double calculateBasLScoreInc (Map<String, Object> LScoreParams){
        Double ownLScore = (Double) LScoreParams.get("ownLScore");
        Double oppLScore = (Double) LScoreParams.get("oppLScore");
        Integer p = (Integer) LScoreParams.get("p");
        Byte categoryId = (Byte) LScoreParams.get("categoryId");

        double a = GameLScoreUtils.getK()*GameLScoreUtils.getG(categoryId, p)*(11000-ownLScore)/5000*(GameLScoreUtils.getW(p)-GameLScoreUtils.getWe(ownLScore, oppLScore));
        double b = (ownLScore - oppLScore > 0)?(int)((ownLScore-oppLScore)/2000)*100*(1-GameLScoreUtils.getW(p)):0.00;
        return GameLScoreUtils.getLScoreIncrement(a, b);
    }

    private double calculateFooLScoreInc (Map<String, Object> LScoreParams){
        Double ownLScore = (Double) LScoreParams.get("ownLScore");
        Double oppLScore = (Double) LScoreParams.get("oppLScore");
        Integer p = (Integer) LScoreParams.get("p");
        Byte categoryId = (Byte) LScoreParams.get("categoryId");

        double a = GameLScoreUtils.getK()*GameLScoreUtils.getG(categoryId, p)*(11000-ownLScore)/5000*(GameLScoreUtils.getW(p)-GameLScoreUtils.getWe(ownLScore, oppLScore));
        double b = (ownLScore - oppLScore > 0)?(int)((ownLScore-oppLScore)/2000)*100*(1-GameLScoreUtils.getW(p)):0.00;
        return GameLScoreUtils.getLScoreIncrement(a, b);
    }

}
